﻿using System.Media;
using System.Windows;

using Utilils;

namespace NAudio.WpfApp;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private Recorder recorder;
    private string filePath;
    private WhisperNet whisperNet;

    public MainWindow()
    {
        InitializeComponent();
        recorder = new Recorder();
        whisperNet = new WhisperNet();
    }

    private void Start_Click(object sender, RoutedEventArgs e)
    {
        Start.IsEnabled = false;
        Stop.IsEnabled = true;
        Play.IsEnabled = false;
        int str = DateTime.Now.ToTimeStamp();
        filePath = $@"C:\Users\Administrator\Desktop\temp\{str}.avi";
        recorder.RecorderStart(filePath);
    }

    private async void Stop_Click(object sender, RoutedEventArgs e)
    {
        Start.IsEnabled = true;
        Stop.IsEnabled = false;
        Play.IsEnabled = true;
        recorder.RecorderStop();
        var list = await whisperNet.StartAsync(filePath);
        foreach (var item in list)
        {
            listBox.Items.Add(item);
        }
    }

    private void Play_Click(object sender, RoutedEventArgs e)
    {
        if (filePath.IsNull())
        {
            return;
        }
        SoundPlayer soundPlayer = new(filePath);
        soundPlayer.Play();
    }
}